/**
 * @param {number[][]} events
 * @return {number}
 */
 var maxTwoEvents = function(events) {
  const n = events.length
  const len = (arr) => (arr[1]-arr[0]+1)
  events.sort((a,b) => {
    if(a[2] === b[2]){
      return len(a) - len(b)
    }
    return b[2] - a[2]
  })
  let ans = events[0][2]
  for(let i = 0; i<n-1; i++){
    if(events[i][2] + events[i+1][2] <= ans) break
    let cur = events[i][2]
    let l = events[i][0], r = events[i][1]
    for(let j = i+1; j<n; j++){
      if(events[j][0] > r || events[j][1] < l){
        ans = Math.max(ans, cur + events[j][2])
        break
      }
    }
  }
  return ans
};